package com.itheima.test22;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.UUID;

/**
 * 编写客户端和服务器端程序，客户端用于上传图片，服务器端用于接收文件，文件上传成功后，
 * 给客户端一个反馈：文件上传成功。
 * <p>
 * 注意：
 * <p>
 * 服务器端采用多线程实现，并且要解决文件名冲突问题。
 */
public class Test22Client {
    public static void main(String[] args) throws IOException {
        for (int i = 0; i < 20; i++) {
            Socket socket = new Socket(InetAddress.getLocalHost(), 55555);
            OutputStream outputStream = socket.getOutputStream();
            BufferedOutputStream bos = new BufferedOutputStream(outputStream);
            BufferedInputStream bis = new BufferedInputStream(new FileInputStream("TEST10.16\\lajiao.jpg"));
            byte[] bytes = new byte[1024];
            int b;
            while ((b = bis.read(bytes)) != -1) {
                bos.write(bytes);
                bos.flush();
            }
            bis.close();
            socket.shutdownOutput();
            BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            System.out.println(br.readLine());
            socket.close();
        }
    }
}
